package com.itcat.api;



import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itcat.api.mysql.PmsBrandApi;


import com.itcat.mapper.PmsBrandMapper;
import com.itcat.mysql.pojo.PmsBrand;
import com.itcat.mysql.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.lang.invoke.LambdaMetafactory;
import java.util.List;

@DubboService
public class PmsBrandApiImpl implements PmsBrandApi {
    @Autowired
    private PmsBrandMapper pmsBrandMapper;

    //品牌管理
    @Override
    public PageResult list(Integer pageNum, Integer pageSize,String keyword) {

        Page<PmsBrand> page = new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<PmsBrand> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(keyword!=null,PmsBrand::getName,keyword);
        pmsBrandMapper.selectPage(page,wrapper);
        List<PmsBrand> records = page.getRecords();
        int count = pmsBrandMapper.selectCount(wrapper);
        PageResult result = new PageResult();
        result.setList(records);
        result.setPageNum(pageNum);
        result.setTotal(count);
        result.setPageSize(pageSize);
        return result;
    }

    /**
     * 修改状态
     * @param ids
     * @param showStatus
     */
    @Override
    public void showStatus(List<Long> ids,Long showStatus) {

        LambdaQueryWrapper<PmsBrand> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(PmsBrand::getId,ids);
        List<PmsBrand> list = pmsBrandMapper.selectList(wrapper);
        for (PmsBrand pmsBrand : list) {

            pmsBrand.setShowStatus(showStatus);
            LambdaQueryWrapper<PmsBrand> wrapper1 = new LambdaQueryWrapper<>();
            wrapper1.eq(PmsBrand::getId,pmsBrand.getId());
            pmsBrandMapper.update(pmsBrand,wrapper1);
        }

    }

    /**
     * 袖带状态
     * @param ids
     * @param showStatus
     */
    @Override
    public void updateFactory(List<Long> ids, Long showStatus) {
        LambdaQueryWrapper<PmsBrand> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(PmsBrand::getId,ids);
        List<PmsBrand> list = pmsBrandMapper.selectList(wrapper);
        for (PmsBrand pmsBrand : list) {

            pmsBrand.setFactoryStatus(showStatus);
            LambdaQueryWrapper<PmsBrand> wrapper1 = new LambdaQueryWrapper<>();
            wrapper1.eq(PmsBrand::getId,pmsBrand.getId());
            pmsBrandMapper.update(pmsBrand,wrapper1);
        }
    }

    /**
     * 品牌查看
     * @param id
     * @return
     */
    @Override
    public PmsBrand selectById(Long id) {
        return pmsBrandMapper.selectById(id);
    }

    /**
     * 商品修改
     * @param id
     * @param pmsBrand
     */
    @Override
    public void updateById(Long id, PmsBrand pmsBrand) {
        pmsBrandMapper.updateById(pmsBrand);
    }

    /**
     * 品牌删除
     * @param id
     */
    @Override
    public void deleteById(Long id) {
        pmsBrandMapper.deleteById(id);
    }

    /**
     * 品牌添加
     * @param pmsBrand
     */
    @Override
    public void createBrand(PmsBrand pmsBrand) {
        pmsBrandMapper.insert(pmsBrand);
    }
}
